var api = require('../../utils/api.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    page:1
  },

  onLoad(options) {

  },

  nexturl(ret){
    console.log(ret);
    var url=ret.currentTarget.dataset.url;

    wx.navigateTo({
      url: url
    })

  },

  onShow() {
      this.setData({
        list:[],
        page:1
      })
    this.getmyorder();
  },

  getmyorder(){
    var that=this;
    var page=this.data.page;
    var lists=this.data.list;


    api.get({
      url: 'wxapp/user/getmyorder',
      data: {page:page},
      success: data => {
          var list=data.data;

        if(list.length>0){

          list.forEach(function (index) {
              console.log(index);
              lists.push(index);

          })

          that.setData({
            list:lists,
            page:page+1
          })

        }

      }
  });

  },

  delete(ret){
    var id=ret.currentTarget.dataset.id;


    var that=this;
  

    wx.showModal({
      title: '提示',
      content: '确定要删除吗?',
      success (res) {
      if (res.confirm) {
    
        api.get({
          url: 'wxapp/user/deletebyid',
          data: {id:id},
          success: data => {

            wx.showToast({
              title: data.msg,
              icon:'none'
            })
            if(data.code==1){
                that.setData({
                    page:1,
                    list:[]
                  });
                that.getmyorder();

            }
            
          }
      });
     
      } 
      }

  
    })

  }
})